package com.jhws.business.local.api;

import com.jhws.business.local.bo.LocalConstant;
import com.jhws.business.local.service.SipAcountSynchService;
import com.jhws.common.base.bo.JsonRespData;
import com.jhws.sys.appUser.bo.TblSipAcountDimBo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;

@Controller
@RequestMapping("/localSynch/sipAcount")
public class SipAcountSynchApi {
    @Resource
    private SipAcountSynchService acountSynchService;

    @RequestMapping(value = "acounts")
    @ResponseBody
    public JsonRespData saveSipAcount(@RequestBody TblSipAcountDimBo sipAcountDimBo) throws Exception {
        if (sipAcountDimBo.getIsSynch() == LocalConstant.SYNCH_STATE_NO) {
            if (acountSynchService.isUserExist(sipAcountDimBo.getUsername())) {
                return new JsonRespData("", 1, "Success");
            }
            acountSynchService.saveSipAcount(sipAcountDimBo);
        } else if ((sipAcountDimBo.getIsSynch() == LocalConstant.SYNCH_STATE_DEL)) {
            acountSynchService.deleteSipAcount(sipAcountDimBo);
        }
        return new JsonRespData("", 1, "");
    }

    @RequestMapping(value = "anon/test")
    @ResponseBody
    public JsonRespData test() throws Exception {
        acountSynchService.mergeSipAcount("http://test.jhws.top:8081/", new HashMap<String, String>() {
            {
                put("commCode", "0008");
                put("commPassword", "201688");
            }
        });
        return new JsonRespData("", 1, "Success");
    }
}
